package vn.fpt.fsoft.menugame;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.font.TextAttribute;
import java.awt.image.BufferedImage;
import java.text.AttributedString;

public class MenuItem {

	private BufferedImage image;
	private int x;
	private int y;
	private String name;
	private boolean isSelect;

	/**
	 * @return the isSelect
	 */
	public boolean isSelect() {
		return isSelect;
	}

	/**
	 * @param isSelect
	 *            the isSelect to set
	 */
	public void setSelect(boolean isSelect) {
		this.isSelect = isSelect;
	}

	/**
	 * Get value of name.
	 * 
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * Set the value for name.
	 * 
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	private Color color;
	// private int menuSelect = 0;
	AttributedString attString;

	/**
	 * Get value of attString.
	 * 
	 * @return the attString
	 */
	public AttributedString getAttString() {
		return attString;
	}

	/**
	 * Set the value for attString.
	 * 
	 * @param attString
	 *            the attString to set
	 */
	public void setAttString(AttributedString attString) {
		this.attString = attString;
	}

	public MenuItem(BufferedImage image, int x, int y, String name, Color color) {
		this.image = image;
		this.x = x;
		this.y = y;
		this.name = name;
		this.color = color;
	}

	public void draw(Graphics2D g2d) {
		g2d.drawImage(image, x, y, null);

		Font font = new Font("Serif", Font.ITALIC, 20);
		g2d.setFont(font);
		FontMetrics fontMetrics = g2d.getFontMetrics();
		int height = fontMetrics.getHeight();
		int width = fontMetrics.stringWidth(name);
		Point posText = new Point(x + (image.getWidth() - width) / 2, y
				+ (image.getHeight() - height) / 2 + 15);

		
		color = isSelect ? Color.WHITE: Color.BLACK;
		attString = new AttributedString(name);
		attString.addAttribute(TextAttribute.FOREGROUND, color, 0,
				name.length());
		attString.addAttribute(TextAttribute.FONT, font);
		
		g2d.drawString(attString.getIterator(), posText.x, posText.y);
	}
}
